/**
 * @author hewei
 * @version 1.0
 * @description: 周赛318 t1
 * @date 2022/11/6 10:31
 */

public class ApplyOperations {

    public int[] applyOperations(int[] nums) {
        int n = nums.length;
        int index = 0;
        for (int i = 0; i < n - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
            if (nums[i] != 0) nums[index++] = nums[i];
        }
        if (nums[n - 1] != 0) nums[index++] = nums[n - 1];
        for (int i = index; i < n; i++) {
            nums[i] = 0;
        }
        return nums;
    }

    public int[] process(int[] nums) {
        int[] res = new int[nums.length];
        int index = 0;
        for (int num : nums) {
            if (num != 0) {
                res[index++] = num;
            }
        }
        return res;
    }
}
